Page({
    data: {
      messages: [
        { text: '你好，请问有什么可以帮您？', isMe: false },
        { text: '我想了解一下活动详情', isMe: true }
      ],
      inputValue: '',
      scrollTo: ''
    },
  
    onInput(e) {
      this.setData({ inputValue: e.detail.value });
    },
  
    onSend() {
      const text = this.data.inputValue.trim();
      if (!text) return;
  
      // 追加本地消息
      const newMsg = { text, isMe: true };
      const messages = [...this.data.messages, newMsg];
  
      this.setData({
        messages,
        inputValue: '',
        scrollTo: `msg${messages.length - 1}`
      });
  
      // 模拟对方回复
      setTimeout(() => {
        const reply = { text: '收到，稍后给您答复～', isMe: false };
        const msgs = [...this.data.messages, reply];
        this.setData({
          messages: msgs,
          scrollTo: `msg${msgs.length - 1}`
        });
      }, 800);
    }
  });